<template>
    <LDrawerForm 
        :visible="visible"  
        :confirmLoading="confirmLoading" 
        :title="title" ref="orgForm" 
        :formAttributes="formAttributes"
        @handleOk="handleOk" 
        @handleCancel="handleCancel"
        @clickEventHandler="clickEventHandler"
        @changeEventHandler="changeEventHandler">
    </LDrawerForm>

</template>

<script>
import LDrawerForm from '@/components/lt/form/LDrawerForm'
import pick from 'lodash.pick'
import request from '@/utils/request'
import defaultSettings from '@/config/defaultSettings'

export default {
    name:'orgForm',
    components:{
        LDrawerForm
    },
    mixins:[],
    data(){
        return{
            title:'详情',
            visible:false,
            confirmLoading: false,
            model:{},
            defaultSettings,
            formAttributes:{
              type:'',//collapse,tabs
              formItems:[
                {
                  title:'标签一',
                  columns:1,
                  fields:[
                    {field:'parentNo',label:'父组织',component:'treeSelect',treeCheckable:false,dictCode:defaultSettings.数据字典.组织下拉树},
                    {field:'orgNo',label:'组织编号',component:'input',rules: [{required: true, message: '请输入组织编号!'}]},
                    {field:'orgName',label:'组织名称',component:'input',rules: [{required: true, message: '请输入组织名称!'}]},
                    {field:'orgOrder',label:'排序',component:'input'},
                    {field:'isUse',label:'是否使用',component:'select',rules: [{ required: true, message: '请选择是否使用!' }],dictCode:'SHIFOU(0/1)',initialValue:'1'},
            
                  ]
                },
              ]

            }

            
        }
            
        
    },
    methods:{
        add () {
            this.edit({});
        },
        edit (record) {
            this.visible = true;
            this.model = Object.assign({}, record);
            this.$nextTick(() => {
                this.$refs.orgForm.getForm().setFieldsValue(pick(this.model,'parentNo','orgNo','orgName','orgOrder','isUse'))
            })
        },
        handleOk(){
            const that = this;
            this.$refs.orgForm.getForm().validateFields((err, values) => {
                if (!err) {
                    that.confirmLoading = true
                    let formData = Object.assign(this.model, values);
                    request({url: '/SysOrgController/save',method: 'post',data: formData}).then((res)=>{
                        if(res.success){
                            that.close()
                            that.$message.success(res.message);
                        }else{
                            that.$message.warning(res.message);
                        }
                    }).finally(() => {
                        that.confirmLoading = false;
                     //   that.close()
                    })
                    
                }
            })
        },
        handleCancel(){
            this.visible=false
        },
        close () {
            this.$emit('close');
            this.visible = false;
        },
         /**
         * 表单内容发生变化
         */
        changeEventHandler(changeItem){
     
        },
        clickEventHandler(field,form){
            
        }

    }
}
</script>